$(document).ready(function () {
    getVipInfo()
    getBusinessCard()
    
});

function getVipInfo() {
    var loadIndex = layer.load(2);
    let datas = {
        url: '/api/user.user/info',
        http_type: 'POST',
        datas: {

        }
    }
    wxx.HttpReqeust(datas, function (response) {
        layer.close(loadIndex)
        if (response.code == 1) {
            $('.headImage').attr('src', response.data.user.avatar);
            $("#nickname").text('昵称：' + response.data.user.nickname);
            $("#beans").text('知识豆：' + response.data.user.beans);
            $("#score").text('我的积分：' + response.data.user.beans);
            if (response.data.user.is_distribution == 200) {
                $('.apply_retail').css('display', 'flex')
                $('.has_retail').css('display', 'none')
            } else if (response.data.user.is_distribution == 100) {
                $('.apply_retail').css('display', 'none')
                $('.has_retail').css('display', 'flex')
            }
        } else {
            layer.alert(response.msg, {title: '温馨提示'});
        }
    });
}

function getBusinessCard() {
    var loadIndex = layer.load(2);
    let datas = {
        url: '/api/user.calling_card/info',
        http_type: 'POST',
        datas: {

        }
    }
    wxx.HttpReqeust(datas, function (response) {
        layer.close(loadIndex)
        if (response.code == 1) {
            $("#name").text(response.data.name);
            $("#position_name").text('职位：' + response.data.position);
            $("#company_name").text('公司名称：' + response.data.company_name);
            $("#company_address").text('公司地址：' + response.data.company_address);
            $("#phone").text('手机号：' + response.data.phone);
            $("#email").text('邮箱：' + response.data.email);
            $("#company_logo").attr('src', response.data.company_logo);
            $("#wc_code").attr('src', response.data.wc_code);
            $("#company_code").attr('src', response.data.company_code);
        } else {
            layer.alert(response.msg, {title: '温馨提示'});
        }
    });
}
function editHeadImage(file){
    var loadIndex = layer.load(2);
    var formData = new FormData();
    formData.append('file', file);
    let jingjiang_userinfo = JSON.parse(localStorage.getItem('jingjiang_userinfo'));

    let datas = {
        url: '/api/common/upload',
        http_type: 'POST',
        contentType:'multipart/form-data',
        datas: formData,
        headers: {
            token: jingjiang_userinfo.token
          },
          accept: 'images', 
    }
    wxx.HttpReqeust(datas, function (response) {
        layer.close(loadIndex)
        if (response.code == 1) {
            // let upload = {
            //     url: '/api/user.user/editAvatar',
            //     http_type: 'POST',
            //     contentType:'application/json',
            //     datas: {
            //         avatar:response.data.url
            //     }
            // }
            // var loadIndex = layer.load(2);
            // wxx.HttpReqeust(upload, function (response) {
            //     layer.close(loadIndex)
            //     if (response.code == 1) {
            //         $('.headImage').attr('src', response.data.user.avatar);
            //     } else {
            //         layer.alert(response.msg, {title: '温馨提示'});
            //     }
            // });
        } else {
            layer.alert(response.msg, {title: '温馨提示'});
        }
    });
}